package com.ecy.quadratic.widget;

import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;

/**
 * Created by Administrator on 2017/6/18.
 */
public class RecyclerViewDetector {
    private ComicReadCallback mCallback;
    private GestureDetector mDetector;

    public RecyclerViewDetector(Context context) {
        mDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                                   float velocityY) {
                if (mCallback != null) {
                    mCallback.onFling();
                }
                return false;
            }
        });

        mDetector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                if (mCallback != null) {
                    mCallback.onClick();
                }
                return false;
            }

            @Override
            public boolean onDoubleTap(MotionEvent e) {
                return false;
            }

            @Override
            public boolean onDoubleTapEvent(MotionEvent e) {
                return false;
            }
        });
    }

    public boolean onTouchEvent(MotionEvent event) {
        return mDetector.onTouchEvent(event);
    }

    public void setComicReadCallback(ComicReadCallback callback) {
        mCallback = callback;
    }
}
